package liumengbaio.lolzhangyoubao.Activity.Fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import liumengbaio.lolzhangyoubao.Activity.Adapter.ViewPager_AllHeroAroundAdapter;
import liumengbaio.lolzhangyoubao.Activity.InFo.FreeHeroInfo;
import liumengbaio.lolzhangyoubao.R;

/**
 * Created by lanouhn on 16/8/23.
 */
public class FragmentHeroAround extends Fragment {
    private TabLayout tabLayoutaround;
    private ViewPager viewPageraround;
    private List<String> tabNames = new ArrayList<>();
    private List<Fragment> fragments = new ArrayList<>();
    ;
    private ViewPager_AllHeroAroundAdapter allHeroAroundAdapter;
    Fragment3D fragment3d;
    FragmentSound fragmentsound;
    public static FragmentHeroAround newInstants(FreeHeroInfo info) {
        FragmentHeroAround fragmentHeroAround = new FragmentHeroAround();
        Bundle bundle = new Bundle();
        bundle.putSerializable("aroundinfo",info);
        fragmentHeroAround.setArguments(bundle);
        return fragmentHeroAround;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_heroaround, null);
        return view;

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView(getView());
        initData();
    }

    private void initView(View view) {
        tabLayoutaround = (TabLayout) view.findViewById(R.id.tab_hero_around);
        viewPageraround = (ViewPager) view.findViewById(R.id.vp_hero_around);

        FreeHeroInfo soundinfo= (FreeHeroInfo) getArguments().getSerializable("aroundinfo");
        FreeHeroInfo info3d= (FreeHeroInfo) getArguments().getSerializable("aroundinfo");
        fragment3d = Fragment3D.newInstants(info3d);
        fragmentsound = FragmentSound.newInstants(soundinfo);
    }

    private void initData() {
        tabNames.add("铃声");
        tabNames.add("3D皮肤");
        fragments.add(fragmentsound);
        fragments.add(fragment3d);
        allHeroAroundAdapter = new ViewPager_AllHeroAroundAdapter(getFragmentManager(), tabNames, fragments);
        viewPageraround.setAdapter(allHeroAroundAdapter);
        tabLayoutaround.setupWithViewPager(viewPageraround);

    }
}
